﻿#ifndef NETSERVER_H
#define NETSERVER_H

#include <QObject>
#include <QThread>
#include "tcpserver.h"

class NetServer : public QObject
{
    Q_OBJECT
public:
    explicit NetServer(QObject *parent = nullptr);
    ~NetServer();
    void Start(quint16 servPort);
    void Stop();
    void Write(const QString &ip,int port,char *data,int len);
    void Read(QString ip,quint16 port,char *data,int len);
signals:
    void sigStart(quint16 servPort);
    void sigStop();
    void sigRead(QString ip,quint16 port,char *data,int len);
    void sigWrite(const QString &ip,
                  int port,char *data,int len);
    void sig_readyRead(QString ip,quint16 port);
    void sig_receiveData(QByteArray data,QString ip,quint16 port);
    void sig_clientConnected(QString ip,quint16 port);
public slots:
    void slotStart(quint16 servPort);
    void slotStop();
    void slotRead(QString ip,quint16 port,char *data,int len);
    void slotWrite(const QString &ip,
                   int port,char *data,int len);
    void SlotreceiveData(QByteArray data,QString ip,quint16 port);
    void slot_readyRead(QString ip,quint16 port);
    void slot_clientConnected(QString ip,int port);
private:
    CTcpServer *_ctcpServer;
    QThread *_thread;
};

#endif // NETSERVER_H
